package com.devilvan.grouping;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class CustomGrouping extends WritableComparator {
    /**
     * 覆写默认构造器，通过反射，构造OrderBean对象
     * 通过反射来构造OrderBean对象
     * 接受到的key2  是orderBean类型，我们就需要告诉分组，以orderBean接受我们的参数
     */
    public CustomGrouping(){
        super(OrderBean.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        OrderBean o1 = (OrderBean) a;
        OrderBean o2 = (OrderBean) b;
        // 将同一组订单分到一组
        return o1.getOrderId().compareTo(o2.getOrderId());
    }
}
